from rest_framework.serializers import ModelSerializer,SerializerMethodField
from .models import *
class CateSerializer(ModelSerializer):
    class Meta:
        model = 'Cate'
        fields = '__all__'
class BookSerializer(ModelSerializer):
    cname = SerializerMethodField(read_only=True)
    def cname_get(self,obj):
        return obj.cate.name
    class Meta:
        model = 'Book'
        fields = '__all__'